package com.qihetimes.earthangel.controller;

import com.qihetimes.earthangel.common.ResponseResult;
import com.qihetimes.earthangel.model.GoodsComment;
import com.qihetimes.earthangel.model.bo.GoodsBO;
import com.qihetimes.earthangel.model.bo.GoodsCommentBO;
import com.qihetimes.earthangel.model.bo.GoodsListBO;
import com.qihetimes.earthangel.model.vo.GoodsVO;
import com.qihetimes.earthangel.model.vo.PageVO;
import com.qihetimes.earthangel.service.IGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 物品
 *
 * @author ：f4cklangzi@gmail.com
 * @date ：Created At 2021/12/12
 */
@Slf4j
@Api(tags = "物品模块")
@RestController
@RequestMapping("/api/goods")
public class GoodsController {
    
    @Resource
    private IGoodsService goodsService;
    
    @ApiOperation(value = "上传物品")
    @PostMapping("/upload")
    public ResponseResult<GoodsVO> upload(@RequestBody GoodsBO param) {
        GoodsVO goods = goodsService.upload(param);
        return ResponseResult.success(goods);
    }
    
    @ApiOperation(value = "编辑物品")
    @PutMapping("/update")
    public ResponseResult<GoodsVO> update(@RequestBody GoodsBO param) {
        GoodsVO goods = goodsService.update(param);
        return ResponseResult.success(goods);
    }
    
    @ApiOperation(value = "物品列表")
    @PostMapping("/list")
    public ResponseResult<PageVO<GoodsVO>> list(@RequestBody GoodsListBO param) {
        PageVO<GoodsVO> page = goodsService.list(param);
        return ResponseResult.success(page);
    }
    
    @ApiOperation(value = "删除物品")
    @DeleteMapping("/delete")
    public ResponseResult<String> delete(@RequestParam String goodsId) {
        goodsService.delete(goodsId);
        return ResponseResult.success();
    }
    
    @ApiOperation(value = "点赞物品")
    @PutMapping("/like")
    public ResponseResult<String> like(@RequestParam String goodsId) {
        goodsService.like(goodsId);
        return ResponseResult.success();
    }
    
    @ApiOperation(value = "评论物品")
    @PutMapping("/comment")
    public ResponseResult<GoodsComment> comment(@RequestBody GoodsCommentBO param) {
        GoodsComment comment = goodsService.comment(param);
        return ResponseResult.success(comment);
    }
    
    @ApiOperation(value = "收藏物品")
    @PutMapping("/favorite")
    public ResponseResult<String> favorite(@RequestParam String goodsId) {
        goodsService.favorite(goodsId);
        return ResponseResult.success();
    }
    
    @ApiOperation(value = "赠送物品")
    @PutMapping("/send")
    public ResponseResult<String> send(@RequestParam String goodsId, @RequestParam String userId) {
        goodsService.send(goodsId, userId);
        return ResponseResult.success();
    }
    
    @ApiOperation(value = "分享物品")
    @PutMapping("/share")
    public ResponseResult<String> share(@RequestParam String goodsId) {
        goodsService.share(goodsId);
        return ResponseResult.success();
    }
}
